Skip to content

Associated type bounds: clarify stuff...#4

Merged
Centril merged 3 commits into
rfc/associated-type-boundsfrom
rfc/associated-type-bounds-patch-2
Jun 11, 2018
Merged

Associated type bounds: clarify stuff...#4
Centril merged 3 commits into
rfc/associated-type-boundsfrom
rfc/associated-type-bounds-patch-2

Conversation

@Centril
Copy link
Copy Markdown
Owner

@Centril Centril commented Jun 8, 2018

See changes ;)

Comment thread text/0000-associated-type-bounds.md Outdated
## Notes on the meaning of `impl Trait<Assoc: Bound>`

Note that in the context `-> impl Trait<Assoc: Bound>`, since the
`Trait` is existentially quantified, so is in effect also the `Assoc`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a bit of grammar cleanup for clarity. How about: since the Trait is existentially quantified, the Assoc is as well.

Comment thread text/0000-associated-type-bounds.md Outdated
fn printables() -> impl Iterator<Item = impl Display> { .. }
```

For `arg: impl Trait<Assoc: Bound>`, it can likewise be seen as:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"it likewise desugars to"

Comment thread text/0000-associated-type-bounds.md Outdated

Note that in the context `-> impl Trait<Assoc: Bound>`, since the
`Trait` is existentially quantified, so is in effect also the `Assoc`.
Semantically speaking, `fn printables..` is equivalent to:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/is equivalent to/desugars to/

For `arg: impl Trait<Assoc: Bound>`, it can likewise be seen as:
`arg: impl Trait<Assoc = impl Bound>`.

## Meaning of `existential type Foo: Trait<Assoc: Bound>`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include notes in this section that 1) reference the existential type RFC by number and 2) explicitly state that "like that RFC, this documentation uses the non-final syntax for existential type aliases".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please edit the tracking issue for that RFC to request that when the syntax gets finalized, this RFC should be updated.

@Nemo157
Copy link
Copy Markdown

Nemo157 commented Jun 8, 2018

I was thinking about my original read of this specifying bounds on existential types again

fn foo() -> impl Iterator<Item: Display> { ... }
existential type _0 where _0: Iterator, <_0 as Iterator>::Item: Display;
fn foo() -> _0 { ... }

This actually makes a lot of sense to me after reconsidering it, extending existential types to be able to carry multiple bounds should be a pretty straightforward extension to their capabilities. Likely the reason it hasn't been mentioned before is that it's unrequired for the main goal of adding a base syntax to represent -> impl Trait functions.

What I'm unsure about is if this differs in any way from the proposed desugaring. For generic parameters there is a difference because adding a new anonymous generic type parameter inhibits turbo-fish, but it seems that existential type declarations don't suffer the same problem.

If it wasn't for the turbo-fish issue it seems that specifying the desugaring as Foo<Bar: Display> -> Foo<Bar = impl Display> could cover generic type parameters and existential types fully (still leaves associated types out, but presumably that would be specified by the "impl Trait in traits" RFC).

@Centril
Copy link
Copy Markdown
Owner Author

Centril commented Jun 9, 2018

This actually makes a lot of sense to me after reconsidering it, extending existential types to be able to carry multiple bounds should be a pretty straightforward extension to their capabilities.

I agree; in any case, the compiler is free to implement this logic internally even if it is not exposed as surface syntax.

What I'm unsure about is if this differs in any way from the proposed desugaring.

So I think the proposed desugaring is still via where (and existential type because that is what I assume -> impl Trait will get desugared to in the future...). I intentionally specified this as the weaker "semantically equivalent to" instead of "desugars to" so that the compiler devs are more free in picking equivalent desugarings.

I don't think there is any observable difference from the user's perspective.

For generic parameters there is a difference because adding a new anonymous generic type parameter inhibits turbo-fish, but it seems that existential type declarations don't suffer the same problem.

Agreed.

@Centril
Copy link
Copy Markdown
Owner Author

Centril commented Jun 11, 2018

Merging then :)

@Centril Centril merged commit 1376723 into rfc/associated-type-bounds Jun 11, 2018
@Centril Centril deleted the rfc/associated-type-bounds-patch-2 branch June 11, 2018 21:42
Centril pushed a commit that referenced this pull request May 5, 2019
Document more Community Team goals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants